package leetcode.code1958;

import leetcode.IDebug;
import leetcode.helper.H;

public class Solution implements IDebug {

	int[] d = new int[] { -1, -1, -1, 0, -1, 1, 0, -1, 0, 0, 0, 1, 1, -1, 1, 0, 1, 1 };

	public boolean checkMove(char[][] board, int rMove, int cMove, char color) {
		for (int i = 0; i < d.length; i += 2) {
			if (this.checkMove(board, rMove, cMove, color, d[i], d[i + 1], 0)) {
				return true;
			}
		}
		return false;
	}

	public boolean checkMove(char[][] board, int rMove, int cMove, char color, int x, int y, int dist) {
		int m = board.length, n = board[0].length;
		if (rMove < 0 || rMove == m || cMove < 0 || cMove == n) {
			return false;
		}
		if (dist == 0 && board[rMove][cMove] != '.') {
			return false;
		}
		if (dist != 0 && board[rMove][cMove] == '.') {
			return false;
		}
		if (dist != 0 && board[rMove][cMove] == color) {
			return dist > 1 ? true : false;
		}
		return this.checkMove(board, rMove + x, cMove + y, color, x, y, dist + 1);
	}

	@Override
	public void debug4() {
		H.compare(true, this.checkMove(H.str2array5(
				"[[\"B\",\"B\",\"B\",\".\",\"W\",\"W\",\"B\",\"W\"],[\"B\",\"B\",\".\",\"B\",\".\",\"B\",\"B\",\"B\"],[\".\",\"W\",\".\",\".\",\"B\",\".\",\"B\",\"W\"],[\"B\",\"W\",\".\",\"W\",\"B\",\".\",\"B\",\".\"],[\"B\",\"W\",\"W\",\"B\",\"W\",\".\",\"B\",\"B\"],[\".\",\".\",\"W\",\".\",\".\",\"W\",\".\",\".\"],[\"W\",\".\",\"W\",\"B\",\".\",\"W\",\"W\",\"B\"],[\"B\",\"B\",\"W\",\"W\",\"B\",\"W\",\".\",\".\"]]"),
				5, 6, 'B'));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
